package com.example.demo.newtouch_ai.my;

import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import com.example.demo.BaseTest;
import org.junit.Test;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: demo_sb
 * @description: 新致AI图像测试
 * @author: luojm
 * @create: 2018-09-20 16:16
 */
public class ImagesTest1 extends BaseTest {
    public static void main(String[] args) {
        // 本地文件路径
        String filePath = "C:\\Users\\luojm\\Desktop\\20180828040121699.jpeg";
        File imgData = new File(filePath);
        String imgStr = Base64.encode(imgData);
        Map<String,Object> param = new HashMap<>(1);
        param.put("image",imgStr);
        param.put("image_type",0);
        JSON json = new JSONObject(param);



        final String url =  "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token="+"24.04c8f47810851211c886aff71cc7d441.2592000.1540609140.282335-14296020";
        String result = HttpRequest.post(url)
                .header("Content-Type", "application/x-www-form-urlencoded")
//                .body(JSONObject.toJSONString(param))
                .body(json)
                .timeout(20000)//超时，毫秒
                .execute().body();
        System.err.println(result);
    }

//    public static void main(String[] args) {
//        Map<String,Object> param = new HashMap<>(1);
//        param.put("images","afddf");
//        Object o = JSONObject.toJSONString(param);
//        System.err.println(o);
//    }
    @Test
    public void bankCardTest(){

    }

}
